package restaurant.selector;

import java.io.IOException;

import restaurant.selector.database.DatabaseManager;
import restaurant.selector.logic.LogicFactory;
import restaurant.selector.logic.LogicInterface;
import restaurant.selector.server.Server;

public class Main {

	private static final String VERSION = "0.1";
	
	public static void main(String[] args) throws IOException {

		Configuration configuration = Configuration.getInstance();
		configuration.init( "config.properties" );
		
		System.out.printf("Restaurant Selector v%s\n", VERSION);
		
		DatabaseManager dbManager = DatabaseManager.getInstance();
		dbManager.init(configuration.getDatabaseDriver(),
				configuration.getDatabaseUser(),
				configuration.getDatabasePassword(),
				configuration.getDatabaseUrl(),
				configuration.getDatabaseStore());

		LogicFactory logicFactory = LogicFactory.getInstance();
		LogicInterface logic = logicFactory.getLogic(configuration.getDatabaseLogic(), dbManager);
		
		if( configuration.getServer()){
			int port = configuration.getServerPort();
			Server server = new Server(port, logic);
			Thread thread = new Thread( server );
			thread.start();
			
			System.out.println("Server started on port " + port);
		}
	}		
}
